package com.woniuxy.credit_loans.accounting_shi.controller;

import com.woniuxy.credit_loans.accounting_shi.service.DebitInfoService;
import com.woniuxy.credit_loans.accounting_shi.vo.DebitVo;
import com.woniuxy.credit_loans.entity.DebitInfo;
import com.woniuxy.credit_loans.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/debits")
public class DebitController {
    @Autowired
    private DebitInfoService debitInfoService;
    @PostMapping("/all")
    public Result c1(){
        List<DebitVo> debitVos = debitInfoService.selectAll();
        return Result.ok().data("debitlist",debitVos);
    }

    @PostMapping("")
    public  Result add(@RequestBody DebitInfo debitInfo){
         int i = debitInfoService.insertSelective(debitInfo);
        if (i==0) {
            return  Result.ok();
        }else {
            return  Result.error();
        }
    }

    @GetMapping("{id}")
    public  Result delete(@PathVariable Long id){
         int i = debitInfoService.deleteByPrimaryKey(id);
        if (i==0) {
            return  Result.ok();
        }else {
            return  Result.error();
        }
    }

}
